package com.boyon.system.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.boyon.hbm.criteria.Query;
import com.boyon.system.entity.Coding;
import com.boyon.system.service.CodingService;
import com.boyon.web.param.annotation.ValidatorRequestBody;
import com.boyon.web.response.PageResponse;
import com.boyon.web.response.SuccessResponse;

/**
 * ClassName:CodingAction <br/>
 * Function: 系统编码设置. <br/>
 * Reason: 设置系统编码生成规则. <br/>
 * Date: 2018年3月14日 下午9:55:37 <br/>
 * 
 * @author sunshulin
 * @version
 * @since JDK 1.8
 * @see
 */
@Controller
@RequestMapping(value = "/boyon/coding", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class CodingAction {

	@Autowired
	private CodingService codingService;

	/**
	 * 
	 * modify:更改编码设置规则. <br/>
	 * 
	 * @author sunshulin
	 * @param coding
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/modify")
	@ResponseBody
	public SuccessResponse modify(@ValidatorRequestBody Coding coding) {
		codingService.updateCoding(coding);
		return new SuccessResponse();
	}
	
	/**
	 * 
	 * start:启用编码. <br/> 
	 * 
	 * @author sunshulin 
	 * @param coding
	 * @return 
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/start")
	@ResponseBody
	public SuccessResponse start(@ValidatorRequestBody Coding coding) {
		codingService.start(coding.getCodingId());
		return new SuccessResponse();
	}

	/**
	 * 
	 * findByCodingId:查找编码设置. <br/>
	 * 
	 * @author sunshulin
	 * @param coding
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/findByCodingId")
	@ResponseBody
	public SuccessResponse findByCodingId(@ValidatorRequestBody Coding coding) {
		return new SuccessResponse(
				codingService.findByCodingId(coding.getCodingId()));
	}

	/**
	 * 
	 * query:系统编码规则列表. <br/>
	 * 
	 * @author sunshulin
	 * @param coding
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/query")
	@ResponseBody
	public PageResponse query(@ValidatorRequestBody Coding coding) {
		Query query = new Query(coding.page());
		return new PageResponse(codingService.query(query));
	}
}
